Fixed get_size() for GtkCellRendererText to clip to the input area
authorTristan Van Berkom <tristan.van.berkom@gmail.com>
Wed, 5 Jan 2011 17:29:18 +0000 (02:29 +0900)
committerTristan Van Berkom <tristan.van.berkom@gmail.com>
Wed, 5 Jan 2011 17:31:42 +0000 (02:31 +0900)
For ellipsize cells it's important to clip the result of get_size()
so that the returned required rectangle is indeed less than or equal
to the input rectangle... this is done so that GtkCellArea can accurately
paint focus on cells by calling gtk_cell_renderer_get_aligned_area().

Patch also adds assertions to gtk_cell_renderer_get_aligned_area() to
ensure this keeps working correctly.

gtk/gtkcellrenderer.c
gtk/gtkcellrenderertext.c

index a6760ee1ac3566fbf4f3149153e7981ea849a947..b2ef07b4a5e759646549c391c4fbc1be911b1d88 100644 (file)
@@ -1657,4 +1657,9 @@ gtk_cell_renderer_get_aligned_area (GtkCellRenderer      *cell,
 
   klass = GTK_CELL_RENDERER_GET_CLASS (cell);
   klass->get_aligned_area (cell, widget, flags, cell_area, aligned_area);
+
+  g_assert (aligned_area->x >= cell_area->x && aligned_area->x < cell_area->x + cell_area->width);
+  g_assert (aligned_area->y >= cell_area->y && aligned_area->y < cell_area->y + cell_area->height);
+  g_assert ((aligned_area->x - cell_area->x) + aligned_area->width <= cell_area->width);
+  g_assert ((aligned_area->y - cell_area->y) + aligned_area->height <= cell_area->height);
 }
index 5f2c2c2f96c88d994ba05ad33a48db5dac5a8938..a54b2745592e1eeaa3e397d9f515528ed6136b6e 100644 (file)
@@ -1736,18 +1736,15 @@ get_size (GtkCellRenderer    *cell,
 
   pango_layout_get_pixel_extents (layout, NULL, &rect);
 
-  if (height)
-    *height = ypad * 2 + rect.height;
-
-  if (width)
-    *width = xpad * 2 + rect.x + rect.width;
-
   if (cell_area)
     {
       gfloat xalign, yalign;
 
       gtk_cell_renderer_get_alignment (cell, &xalign, &yalign);
 
+      rect.height = MIN (rect.height, cell_area->height - 2 * ypad);
+      rect.width  = MIN (rect.width, cell_area->width - (2 * xpad) - rect.x);
+
       if (x_offset)
        {
          if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
@@ -1770,6 +1767,12 @@ get_size (GtkCellRenderer    *cell,
       if (y_offset) *y_offset = 0;
     }
 
+  if (height)
+    *height = ypad * 2 + rect.height;
+
+  if (width)
+    *width = xpad * 2 + rect.x + rect.width;
+
   g_object_unref (layout);
 }